<template>
    <glsx-dialog :show="value" title="导出排重包" @close="closeDialog" width="450px">
        <el-form ref="addForm" class="add_hospital_form" size="small" :model="addForm" :rules="addFormRules">
            <el-form-item label="请选择导出城市：" prop="city">
                <el-select v-model="addForm.city">
                    <el-option v-for="(item, index) in cityList" :key="`city_${index}`" :value="item"
                        :label="item"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button type="primary" size="small" @click="saveInfo">保存</el-button>
            <el-button type="default" size="small" @click="closeDialog">取消</el-button>
        </div>
    </glsx-dialog>
</template>
<script>
import { GET_EXPORT_CITY } from '@/http/public'
import { EXPORT_CUSTOMER_PCH } from '@/http/customer'
import { showModal, deepClone } from "@/utils/util";
export default {
    name: 'DownloadPopup',
    props: {
        value: {
            type: Boolean,
            default: false
        },
    },
    data() {
        return {
            addForm: {},
            addFormRules: {
                city: [{ required: true, message: '请选择导出城市', trigger: 'change' }]
            },
            cityList: [],
            loading: false
        };
    },
    created() {
        this.getList()
    },
    mounted() {

    },
    methods: {

        // 关闭弹框
        closeDialog() {
            this.$emit('input', false)
            this.$emit('change', false)
        },

        // 获取城市
        async getList() {
            let res = await GET_EXPORT_CITY()
            console.log(res)
            this.cityList = res.data || []
        },

        // 保存数据
        saveInfo() {
            let _this = this;
            _this.$refs.addForm.validate(valid => {
                if (!valid) {
                    return false;
                }
                let oParams = deepClone(_this.addForm);
                _this.loading = true
                EXPORT_CUSTOMER_PCH(oParams).then(res => {
                    _this.loading = false
                    if (res.code == 200) {
                        showModal({
                            //message: '导出“选择的城市”MD排重包成功，生成排重包需要时间，稍后请到以下位置下载：“系统配置-文件下载”',
                            message: res.message,
                            type: 'success',
                            success: function () {
                                _this.closeDialog()
                            }
                        })
                    }
                })

            })
        }


    },
};
</script>
<style lang="scss" scoped></style>
  